/*
 * File    : /services/joi.use.js
 * Time    : 2021-03-30 21:32:47
 * Author  : Gray Snail
 * Version : 1.0
 * Contact : shtao2011@sina.com
 * License : Copyright (c) 2021 Gray Snail
 * Desc    : None
 */
const Joi = require('joi')

const schema = Joi.object({
  username: Joi.string().alphanum().min(3).max(30).required(),
  password: Joi.string().regex(/^[a-zA-Z0-9]{3,30}$/),
  access_token: [Joi.string(), Joi.number()],
  birthyear: Joi.number().integer().min(1900).max(2013),
  email: Joi.string().email(),
})
  .with('username', 'birthyear')
  .without('password', 'access_token')

const data = {
  username: '1a',
}

const { error, value } = schema.validate(data)
console.log(error.message)
console.log(value)
